package org.uugu.util;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@Component("upload")
@Scope("prototype")  

public class UploadUtil extends ActionSupport{
	 
	/**
	 * 文件上传类
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private File uploadFile;
	private String uploadFileFileName;
	
	@Override
	public String execute() throws Exception {
		System.out.println("1111111111111111111111111111111");
		String targetDirectory = ServletActionContext.getRequest().getRealPath("/upload");
		File target = new File(targetDirectory, uploadFileFileName);
		FileUtils.copyFile(uploadFile, target);
		return "uploadSuccess";
	}
	@Override
	public void validate() {
		
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public File getUploadFile() {
		return uploadFile;
	}
	public void setUploadFile(File uploadFile) {
		this.uploadFile = uploadFile;
	}
	public String getUploadFileFileName() {
		return uploadFileFileName;
	}
	public void setUploadFileFileName(String uploadFileFileName) {
		this.uploadFileFileName = uploadFileFileName;
	}

}
